#! /usr/bin/env python
# -*- coding: utf8 -*-

import zope.interface

import base

class deleteTree(object):
    zope.interface.implements(base.IAlgorithm)
    name = "deleteTree"

    def __init__(self, node):
        pass

    def __call__(self, node, parentMap, root):
        if node not in parentMap:
            return

        keys = node[:]

        if node in parentMap[node]:
            parentMap[node].remove(node)
            parentMap.pop(node)

        [(parentMap[x].remove(x), parentMap.pop(x)) for x in node.findall(".//*") if x in parentMap.keys()]
        return -2

__plugins__ = (deleteTree, )
